#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int minPathSum(vector<vector<int>>& grid) {
        int row=grid.size();
        int col=grid[0].size();
        vector<vector<int>>dp(row+1,vector<int>(col+1,0));
        for(int i=2;i<=col;i++)
            dp[0][i]=INT_MAX;
        for(int i=1;i<=row;i++)
            dp[i][0]=INT_MAX;

        for(int i=1;i<=row;i++)
        {
            for(int j=1;j<=col;j++)
            {
                dp[i][j]=min(dp[i-1][j],dp[i][j-1])+grid[i-1][j-1];
            }
        }
        return dp[row][col];

        
    }
};